package lumis.portal.serialization;

import java.util.Map;

import lumis.portal.PortalException;
import lumis.portal.manager.ManagerException;
import lumis.portal.serialization.persistency.IDirectory;

/**
 * Manager interface for portal objects serialization and deserialization
 *
 * @version $Revision: 10825 $ $Date: 2009-08-04 12:36:40 -0300 (Tue, 04 Aug 2009) $
 * @since 4.0.7
 */
public interface ISerializationManager2
{
	/**
	 * Attribute set in the transaction indicating that serialization is in execution.
	 * @since 5.0.0
	 */
	public static final String ATTRIBUTE_SERIALIZING = "lumis.portal.serialization.SerializationManager2#ATTRIBUTE_SERIALIZING";
	
	/**
	 * Attribute set in the transaction indicating that deserialization is in execution.
	 * @since 4.2.1
	 */
	public static final String ATTRIBUTE_DESERIALIZING = "lumis.portal.serialization.SerializationManager2#ATTRIBUTE_DESERIALIZING";

	// CHANNEL SERIALIZATION
	
	/**
	 * Serialize a channel to a xml file.
	 * @param serializationContext context object that contains all operation settings
	 * @throws ManagerException
	 * @throws PortalException
	 */
	public void serializeChannel(SerializationContext serializationContext) throws ManagerException, PortalException;

	/**
	 * Serialize a channel to a xml file asynchronously.
	 * @param serializationContext context object that contains all operation settings
	 * @throws ManagerException
	 * @throws PortalException
	 */
	public void beginSerializeChannel(SerializationContext serializationContext) throws ManagerException, PortalException;
	
	// CHANNEL DESERIALIZATION
	
	/**
	 * Deserialize a channel from a xml file.
	 * @param deserializationContext context object that contains all operation settings
	 * @return
	 * @throws ManagerException
	 * @throws PortalException
	 */
	public String deserializeChannel(DeserializationContext deserializationContext) throws ManagerException, PortalException;

	/**
	 * Deserialize a channel from a xml file asynchronously.
	 * @param deserializationContext context object that contains all operation settings
	 * @throws ManagerException
	 * @throws PortalException
	 */
	public void beginDeserializeChannel(DeserializationContext deserializationContext) throws ManagerException, PortalException;

	// PAGE SERIALIZATIOJN

	/**
	 * Serialize a page to a xml file.
	 * @param serializationContext context object that contains all operation settings
	 * @param pageId page to be serialized
	 * @param setupSerializationContext indicates if the serialization settings must be set before the operation
	 * @throws ManagerException
	 * @throws PortalException
	 */
	public void serializePage(SerializationContext serializationContext, String pageId, boolean setupSerializationContext) throws ManagerException, PortalException;

	// PAGE DESERIALIZATION
	
	/**
	 * Deserialize a page from a xml file.
	 * @param deserializationContext context object that contains all operation settings
	 * @param pageId page to be deserialized 
	 * @param setupSerializationContext indicates if the serialization settings must be set before the operation
	 * @param checkUnresolvedDependencies indicates when the existence of unresolved dependencies must raise a {@link SerializationException}
	 * @throws ManagerException
	 * @throws PortalException
	 */
	public void deserializePage(DeserializationContext deserializationContext, String pageId, boolean setupSerializationContext, boolean checkUnresolvedDependencies) throws ManagerException,
			PortalException;

	// OBJECT SERIALIZATION
	
	/**
	 * Serialize an object to a xml String. 
	 * @param o object to be serialized
	 * @param alias alias (tag name) for the object
	 * @return
	 * @throws SerializationException
	 */
	public String serializeObjectToString(Object o, String alias) throws SerializationException;

	/**
	 * Serialize an object to a xml String, using custom serialization settings 
	 * @param o object to be serialized
	 * @param alias alias (tag name) for the object
	 * @param serializationSettings serialization settings for the operation
	 * @return
	 * @throws SerializationException
	 */
	public String serializeObjectToString(Object o, String alias, SerializationSettings serializationSettings) throws SerializationException;

	/**
	 * Serialize an object to a xml String, using a given XStream object 
	 * @param o object to be serialized
	 * @param alias alias (tag name) for the object.
	 * @param serializer the object serializer instance.
	 * @return String representation of the object.
	 * @throws SerializationException
	 */
	public String serializeObjectToString(Object o, String alias, ISerializer serializer) throws SerializationException;
	
	public void serializeObject(Object o, IDirectory directory, String filePath, String alias) throws SerializationException;

	public void serializeObject(Object o, IDirectory directory, String filePath, String alias, SerializationSettings serializationSettings) throws SerializationException;

	/**
	 * Serializes an object to a file in a directory.
	 * @param object the object.
	 * @param directory the directory.
	 * @param filePath the file path in the directory.
	 * @param alias the alias for the object.
	 * @param serializer the object serializer instance.
	 * @since 5.0.0
	 */
	public void serializeObject(Object object, IDirectory directory, 
			String filePath, String alias, ISerializer serializer) throws SerializationException;

	/**
	 * Serializes a Map object where the name and value are of type String.
	 * 
	 * @param map the map object to be serialized.
	 * @param directory the directory objecto to be serialized to.
	 * @param filePath the file path within the directory.
	 * @param alias alias to use for the Map object.
	 * @throws SerializationException
	 * @since 5.0.0
	 */
	public void serializeMap(Map<String, String> map, IDirectory directory, String filePath, String alias) throws SerializationException;
	
	// OBJECT DESERIALIZATION
	
	public <T> T deserializeObject(Class<T> objectClass, IDirectory directory, String filePath, String alias, SerializationSettings serializationSettings, boolean fileIsOptional) throws SerializationException;

	public <T> T deserializeObject(Class<T> objectClass, IDirectory directory, String filePath, String alias, boolean fileIsOptional) throws SerializationException;

	/**
	 * Deserializes an object from a file in a directory.
	 * @param <T> the object type.
	 * @param objectClass the object class type.
	 * @param directory the directory.
	 * @param filePath the file path in the directory.
	 * @param alias the alias for the object.
	 * @param serializer the object serializer instance.
	 * @param fileIsOptional if <code>true</code>, the file may not exist, 
	 * which causes the return to be <code>null</code>.
	 * @return the deserialized object, or <code>null</code> if 
	 * <code>fileIsOptional</code> is true and the file is not found.
	 * @since 5.0.0
	 */
	public <T> T deserializeObject(Class<T> objectClass, IDirectory directory, 
			String filePath, String alias, ISerializer serializer, 
			boolean fileIsOptional) throws SerializationException;
	
	// GENERAL
	
	@Deprecated
	public SerializationSettings getExternalDependenciesSerializationSettings();
}